package com.jsgt.greekfire.repository

import com.jsgt.greekfire.bean.*
import com.jsgt.greekfire.common.http.*
import com.jsgt.greekfire.dao.model.MarketBean
import com.jsgt.greekfire.ui.mine.sermoncommunity.Community
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * author fhx
 * create time 2020/4/25 18:20
 **/
class CoinRepository : BaseRepository() {
    companion object {
        val instance = CoinRepository()
    }

    /**
     * 获取我的行情列表
     */
    suspend fun getMyMarketList(params: Map<String, Any>): ResponseData<List<CoinBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.getMyMarketList(parseBody(params))
        }

    /**
     * 行情列表
     */
    suspend fun getMarketList(): ResponseData<List<MarketBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.createOKEXService().getMarketsList()
        }

    /**
     * 行情详情
     */
    suspend fun getMarketInfo(guid: String): ResponseData<CoinBean> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.getMarketInfo(guid)
        }

    /**
     * 通过币名称获取行情
     */
    suspend fun getMarketInfoByName(): ResponseData<CoinBean> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.getMarketInfoByName()
        }

    /**
     * 添加自选
     */
    suspend fun addSelfMarket(params: Map<String, Any>): ResponseData<CoinBean> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.addSelfMarket(parseBody(params))
        }

    /**
     * 我的行情自选
     */
    suspend fun getMySelfMarketInfo(params: Map<String, Any>): ResponseData<CoinBean> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.getMySelfMarketInfo(parseBody(params))
        }

    /**
     * 删除我的自选
     */
    suspend fun deleteMyMarket(params: Map<String, Any>): ResponseData<CoinBean> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.deleteMyMarket(parseBody(params))
        }

    /**
     * 抢购列表
     */
    suspend fun snappedUpCoinList(): ResponseData<List<SnapUpBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.snappedUpCoinList()
        }

    /**
     * 抢购
     */
    suspend fun snappedUpCoin(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.snappedUpCoin(parseBody(params))
        }

    /**
     * 推荐币种
     */
    suspend fun coinTypeList(): ResponseData<List<CoinBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.coinTypeList()
        }

    /**
     * 提币
     */
    suspend fun withdrawCoin(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.withdrawCoin(parseBody(params))
        }

    /**
     * 买卖币
     */
    suspend fun sellCoin(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.sellCoin(parseBody(params))
        }

    /**
     * 出售列表
     */
    suspend fun saleCoinList(): ResponseData<List<CoinBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.saleCoinList()
        }

    /**
     * 充币地址
     */
    suspend fun rechargeAddress(params: Map<String, Any>): ResponseData<RechargeAddressBean> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.rechargeAddress(parseBody(params))
        }

    /**
     * 个人充币地址
     */
    suspend fun getRechargeAddress(): ResponseData<RechargeAddress> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.getRechargeAddress()
        }

    /**
     * 买币
     */
    suspend fun buyCoin(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.buyCoin(parseBody(params))
        }

    /**
     * 转入转出
     */
    suspend fun rollInOrOut(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.rollInOrOut(parseBody(params))
        }

    /**
     * 资产管理coin状态更新
     */
    suspend fun userAssetUpdate(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.userAssetUpdate(parseBody(params))
        }

    /**
     * 转账
     */
    suspend fun transferToAddress(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.transferToAddress(parseBody(params))
        }

    /**
     * 获取管理费列表
     */
    suspend fun getManagerCharge(guid: String): ResponseData<List<ManageBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.getManagerCharge(guid)
        }

    /**
     * 划转
     */
    suspend fun exchange(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.exchange(parseBody(params))
        }

    /**
     * usdt兑换GFC
     */
    suspend fun u2GFC(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.u2GFC(parseBody(params))
        }

    /**
     * 交易涨跌列表
     */
    suspend fun saleList(params: Map<String, Any>): ResponseData<List<CoinBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.saleList(parseBody(params))
        }

    /**
     * 取消挂单
     */
    suspend fun cancelOrder(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.cancelOrder(parseBody(params))
        }

    /**
     * 获取USTD换算比例
     */
    suspend fun getUSTDPrice(): PriceBean =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.getUstdPrice()
        }

    /**
     * 收益记录
     */
    suspend fun getIncomeList(params: Map<String, Any>): ResponseData<ResultData<IncomeRecordBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.getIncomeList(parseBody(params))
        }

    /**
     * 抢购限制
     */
    suspend fun residueAmount(params: Map<String, Any>): ResponseData<Double> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.residueAmount(parseBody(params))
        }

    /**
     * 创建区块检查相关状态
     */
    suspend fun checkGenesisBlock(): ResponseData<GenesisBlockStatusBean> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.checkGenesisBlock()
        }

    /**
     * 创世区块配置中的状态
     */
    suspend fun checkGenesisBlockStatus(): ResponseData<BlockStatus> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.checkGenesisBlockStatus()
        }

    /**
     *  用户参与 创世区块 抢购
     */
    suspend fun checkGenesisBlockparticipate(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.checkGenesisBlockparticipate(parseBody(params))
        }


    /**
     * 参与创世区块
     */
    suspend fun joinGenesisBlock(): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.joinGenesisBlock()
        }


    /**
     *
     * ResponseData<ResultData<MinerBean>> =
     *  布道社区
     */
    suspend fun myCommunity(params: Map<String, Any>): ResponseData<Community> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.myCommunity(parseBody(params))
        }


    /**
     * 用户闪兑接口
     * http://ip:8081/greekfire/api/gfcuserasset/convert
     */
    suspend fun convert(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.convert(parseBody(params))
        }

    /**
     * 转入
     * http://ip:8081/greekfire/api/gfcuserasset/poolIn
     */
    suspend fun poolIn(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.poolIn(parseBody(params))
        }

    /**
     * 转出
     * http://ip:8081/greekfire/api/gfcuserasset/poolOut
     */
    suspend fun poolOut(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.poolOut(parseBody(params))
        }

    /**
     * 兑换配置列表
     */
    suspend fun convertConfigList(): ResponseData<List<ConvertConfigBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.convertConfigList()
        }

    /**
     * 兑换
     */
    suspend fun convertCoin(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.coinService.convertCoin(parseBody(params))
        }

}